﻿using System.IO;
using System.Xml.Serialization;

namespace Quiz_Builder.Helpers
{
    public class XmlHelper
    {
        public static T XmlToObject<T>(string xml)
        {
            using (var reader = new StringReader(xml))
            {
                var serializer = new XmlSerializer(typeof (T));
                return (T) serializer.Deserialize(reader);
            }
        }

        public static string ObjectToXml<T>(T obj)
        {
            using (var writer = new StringWriter())
            {
                var serializer = new XmlSerializer(typeof (T));
                serializer.Serialize(writer, obj);
                return writer.ToString();
            }
        }
    }
}